package ntust.tw.embedded_project_v1;

import static android.provider.BaseColumns._ID;
import static ntust.tw.embedded_project_v1.DbConstants.TABLE_NAME;
import static ntust.tw.embedded_project_v1.DbConstants.BOOKNAME;
import static ntust.tw.embedded_project_v1.DbConstants.AUTHOR;
import static ntust.tw.embedded_project_v1.DbConstants.PUBLISHER;
import static ntust.tw.embedded_project_v1.DbConstants.PIC;
import static ntust.tw.embedded_project_v1.DbConstants.EXPERIENCE;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {
	
	private final static String DATABASE_NAME = "CustomerInfo.db";
	private final static int DATABASE_VERSION = 1;
	
	public DbHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {		
		final String INIT_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
								  _ID + " INTEGER PRIMARY KEY, " +
								  BOOKNAME + " TEXT, " +
								  AUTHOR + " TEXT, " +
								  PUBLISHER + " TEXT, " +
								  PIC + " BLOB, " +
								  EXPERIENCE + " TEXT);";
		db.execSQL(INIT_TABLE);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
		db.execSQL(DROP_TABLE);
		onCreate(db);
	}

}